package com.course.controller;

import com.course.entity.dto.BigCourseTypeDto;
import com.course.entity.dto.CourseDto;
import com.course.entity.dto.SmallCourseTypeDto;
import com.course.entity.vo.BigCourseTypeVo;
import com.course.service.IBigCourseTypeService;
import com.easyCode.feature.mybaits.CustomPage;
import com.easyCode.feature.result.ResponseResultAdvice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Positive;
import java.util.List;

/**
 * @author zdh
 */
@Validated
@RestController
@RequestMapping("/bigCourseType")
@RequiredArgsConstructor
@ResponseResultAdvice
@Api(tags = "课程大分类请求")
public class BigCourseTypeController {
    private final IBigCourseTypeService iBigCourseTypeService;

    @ApiOperation("新增课程大分类")
    @PostMapping("/save")
    public Integer saveBigCourseType(@Validated BigCourseTypeVo bigcoursetypeVo) {
        return iBigCourseTypeService.saveBigCourseType(bigcoursetypeVo);
    }

    @ApiOperation("根据id查询课程大类")
    @GetMapping("/{id}")
    public BigCourseTypeDto getBigCourseType(@Positive(message = "id不合法")@PathVariable("id") Integer id) {
        return iBigCourseTypeService.getBigCourseTypeById(id);
    }

    @ApiOperation("分页批量查询课程大类")
    @GetMapping("/list")
    public List<BigCourseTypeDto> listBigCourseType(CustomPage customPage) {
        return iBigCourseTypeService.listBigCourseType(customPage);
    }

    @ApiOperation("列举课程大类下的课程小类")
    @GetMapping("/smallCourseTypes/{id}")
    public List<SmallCourseTypeDto> listSmallCourseTypes(@Positive(message = "id不合法")@PathVariable("id") Integer id, CustomPage customPage){
        return iBigCourseTypeService.listSmallCourseTypes(id,customPage);
    }


    @ApiOperation("删除课程大类")
    @DeleteMapping("/{id}")
    public void delBigCourseType(@Positive(message = "id不合法")@PathVariable("id") Integer id) {
        iBigCourseTypeService.delBigCourseTypeById(id);
    }
}
